home *** CD-ROM | disk | FTP | other *** search
- set output error
-
- display _new in blue /*
- */ "Loading QC.Kit Release 2.0 Demonstration Version" _n /*
- */ "Copyright (c) 1986-1988 by ==C=R=C==. All rights reserved."
-
- /*
- User's wishing to edit QC.Kit please see comments at end of this file.
- */
-
-
- /*
- cchart defects unit, graph_options
- */
-
- capture program drop cchart
- program define cchart
- if "%_*"=="" {
- #delimit ;
- di in bl "-> cchart defects unit [, graph_options]" _n
- in ye _col(11) "defects " in gr
- "- the number of defects in each inspection unit" _n in ye
- _col(14) "unit " in gr
- "- the inspection unit number (need not be in order)";
- #delimit cr
- exit
- }
- mac def _varlist "req ex min(2) max(2)"
- mac def _options "*"
- parse "%_*"
- parse "%_varlist", parse(" ")
- mac def _DEFECTS "%_1"
- mac def _UNIT "%_2"
- capture drop _NUNITS
- capture drop _CBAR
- /*
- calculate _CBAR, the mean number of defects
- */
- gen int _NUNITS = sum(%_DEFECTS~=. & %_DEFECTS>=0 & %_UNIT~=.)
- gen float _CBAR = sum(%_DEFECTS)
- mac def _CBAR = _CBAR[_N]/_NUNITS[_N]
- drop _CBAR
- /*
- calculate the control limits and draw the c-chart
- */
- mac def _UCL = %_CBAR + 3*sqrt(%_CBAR)
- mac def _LCL = cond(%_CBAR>3*sqrt(%_CBAR),%_CBAR-3*sqrt(%_CBAR),%_UCL)
- quietly replace _NUNITS = sum(%_DEFECTS<%_LCL | %_DEFECTS>%_UCL)
- mac def _top "(1 unit is out of control)"
- if _NUNITS[_N]!=1 {
- mac def _top = _NUNITS[_N]
- mac def _top = "(%_top units are out of control)"
- }
- #delimit ;
- gr %_DEFECTS %_UNIT, c(l) s(o) sort %_options
- rlab(%_CBAR,%_UCL,%_LCL) yline(%_UCL,%_LCL)
- t1("%_top") l1("Number of defects") ;
- #delimit cr
- drop _NUNITS
- end
-
-
- capture program drop pchart
- program define pchart
- if "%_*"=="" {
- #delimit ;
- di in bl
- "-> pchart rejects unit smplsize [, stabilized graph_options]"
- _n in ye
- _col(11) "rejects" in gr
- " - the number rejected in each inspection unit" _n in ye
- _col(14) "unit" in gr
- " - the inspection unit number (need not be in order)" _n in ye
- _col(10) "smplsize" in gr " - the number in each inspection unit" ;
- #delimit cr
- exit
- }
- mac def _varlist "req ex min(3) max(3)"
- mac def _options "STAbilized *"
- parse "%_*"
- parse "%_varlist", parse(" ")
- mac def _rejects "%_1"
- mac def _unit "%_2"
- mac def _sample "%_3"
- capture drop _ntotal
- capture drop _p
- capture drop _pbar
- /*
- calculate _p, the fraction rejected
- */
- gen _temp = -%_sample
- sort _temp
- drop _temp
- gen int _ntotal = sum(max(0,(%_sample)))
- if _ntotal[_N] <= 0 {
- di in red "All samples are missing or zero"
- drop _ntotal
- exit
- }
- gen float _p = cond(%_rejects/%_sample>=0,%_rejects/%_sample,.)
- label variable _p "Fraction defective"
- gen float _pbar = sum(max(0,%_rejects))
- mac def _pbar = _pbar[_N]/_ntotal[_N]
- drop _pbar
- if %_pbar <= 0 {
- di in red "No units were ever rejected"
- drop _ntotal _p
- exit
- }
- /*
- calculate the control limits
- */
- quietly count if %_sample>0 & %_sample!=. & %_sample!=%_sample[1]
- if _result(1)==0 { /* constant sample size */
- mac def _ucl=3*sqrt(%_pbar*(1-%_pbar)/(%_sample)) + %_pbar
- mac def _lcl=cond(%_pbar>%_ucl-%_pbar,2*%_pbar-%_ucl,%_ucl)
- quietly replace _ntotal = sum(_p<%_lcl | _p>%_ucl)
- mac def _t2=_ntotal[_N]
- mac def _t2="%_t2 units are out of control"
- format _p %9.4f
- #delimit ;
- gr _p %_unit, c(l) s(o) sort %_options
- t1("%_t2") yline(%_ucl,%_lcl)
- rlab(%_ucl,%_lcl,%_pbar)
- l1("Fraction defective") ;
- #delimit cr
- drop _ntotal _p
- exit
- }
- /* varying sample size */
- gen float _ucl = 3*sqrt(%_pbar*(1-%_pbar)/(%_sample))
- gen float _lcl = cond(%_pbar>_ucl,%_pbar-_ucl,.)
- quietly replace _ucl = %_pbar + _ucl
- label variable _ucl " "
- label variable _lcl " "
-
- quietly replace _ntotal = sum(_p<_lcl | _p>_ucl)
- mac def _t2=_ntotal[_N]
- mac def _t2 "%_t2 units are out of control"
- if "%_stabili"=="" {
- format _lcl %9.4f
- #delimit ;
- gr _lcl _ucl _p %_unit, c(lll) s(iio) sort %_options pen(112)
- rlab(%_pbar) t1("%_t2") l1("Fraction defective") ;
- #delimit cr
- drop _ntotal _p _lcl _ucl
- exit
- }
- quietly replace _ntotal = sum(_ucl~=_ucl[1])
- quietly replace _ucl = (_ucl-%_pbar)/3
- quietly replace _p = (_p-%_pbar)/_ucl
- format _p %9.2f
- #delimit ;
- gr _p %_unit, c(l) s(o) sort
- yline(-3,3) %_options
- rlabel(-3,0,3)
- t1("Stabilized p-Chart, average number of defects = %_pbar")
- t2("%_t2")
- l1("Fraction defective") l2("(Standard Deviation units)") ;
- #delimit cr
- drop _ntotal _p _lcl _ucl
- end
-
-
-
- capture program drop plotebar
- program define plotebar
- if "%_*"=="" {
- #delimit ;
- di in bl
- "-> plotebar mean std time [, scale(#) graph_options]" _n
- _col(13) in ye "mean"
- in gr " - process mean" _n
- _col(14) in ye "std"
- in gr " - process standard deviation" _n
- _col(13) in ye "time"
- in gr " - time variable" _n
- _col(16) in ye "# "
- in gr "- number of standard deviations, default is 1" ;
- #delimit cr
- exit
- }
- mac def _varlist "req ex min(3) max(3)"
- mac def _options "SCale(int 1) *"
- parse "%_*"
- parse "%_varlist", parse(" ")
- mac def _mean "%_1"
- mac def _std "%_2"
- mac def _time "%_3"
- /*
- For non-demonstration version, we should save the
- data at this point
- */
- quietly {
- drop if %_mean==. | %_std==. | %_time==.
- keep %_mean %_std %_time
- expand =4, clear
- sort %_time
- gen int _type=mod(_n,4)
- gen double _result=%_mean if _type<=1
- replace _result=%_mean+%_scale*%_std if _type==2
- replace _result=%_mean-%_scale*%_std if _type==3
- }
- gr %_mean _result %_time, c(.l) sy(Oi) %_options
- /*
- For non-demonstration version, we should now
- restore the data
- */
- end
-
-
- di
- di in gr "The following new commands are now available:"
- di " cchart pchart plotebar"
- exit
-
-
- Notes to User's wishing to edit this file:
-
- These comments are placed at the end of the file, after the exit, so that
- Stata does not have to read through them every time the user types "run
- QC.Kit"
-
- Feel free to edit this file and delete programs in which you have no interest.
- Before editing this file, however, make sure the the original is BACKED UP.
- Please do not remove the copyright notice at the top of this file.
-
- If you do edit the file, you should add a display command at the top of this
- file indicating that you have edited the file. You should change the display
- just above these comments that lists the new commands now available.
-
-
- <end of QC.Kit>